<template>
  <el-dialog
    v-model="store.isVisible"
    :title="store.title()"
    width="400px"
    @close="store.cancel()"
  >
    <el-card>
      <el-input
        :type="store.isPassword ? 'password' : 'text'"
        v-model="store.value"
        :class="{ 'is-invalid': !store.isValid }"
        @keypress="store.handleKeyPress"
        :placeholder="store.placeholder || ''"
        clearable
      />
    </el-card>
    
    <template #footer>
      <el-button @click="store.cancel()">
        {{ t('Cancel') }}
      </el-button>
      <el-button 
        type="primary" 
        :disabled="!store.isValid"
        @click="store.confirm()"
      >
        {{ t('OK') }}
      </el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { useInputStringStore } from '@/stores/inputString'
import { useLanguageStore } from '@/stores/language'

const store = useInputStringStore()
const languageStore = useLanguageStore()

// 翻译函数
const t = (key) => {
  const translations = {
    'OK': {
      'en': 'OK',
      'zh': '确认'
    },
    'Cancel': {
      'en': 'Cancel',
      'zh': '取消'
    }
  }
  return translations[key]?.[languageStore.isChinese ? 'zh' : 'en'] || key
}
</script>